<template>
	<view class="upload-img">
		<view class="base-info">
			<view class="uni-flex uni-row uni-mb-5 delay-item">
				<view class="uni-flex uni-column left-info">
					<view class="text title">
						{{data.caseId}}<text v-if="data.selfId&&data.selfId.length">({{data.selfId}})</text>
					</view>
					<view class="uni-flex uni-row">
						<view class="date plain-number">{{data.flaightNo}}</view>
						<view class="date">{{data.flaightTime}}</view>
					</view>
				</view>
				<view class="text uni-flex right-status">
					<text class="status" style="background-color:#0c6eb7;border:solid 1px #0c6eb7;" v-if="data.eventType=='less'">少收</text>
					<text class="status" style="background-color:#85B100;border:solid 1px #85B100;" v-else-if="data.eventType=='more'">多收</text>
					<text class="status" style="background-color:#FF9800;border:solid 1px #FF9800;" v-else-if="data.eventType=='damage'">破损</text>
				</view>
			</view>
		</view>
		<view class="uni-pb-15">
			<!-- <uni-section title="事故、旅客、行李资料" type="line">
				<view class="example-body">
					<easy-upload class="easy-upload" :dataList="formData.passenger" :autoUpload="true"
						:uploadUrl="getUploadUrl('passenger')" :uploadCount="20"
						@successImage="successImage($event,1,'passenger')" @successDeleteImg="successDeleteImg($event,'passenger')" />
				</view>
			</uni-section> -->
			<uni-section title="事故信息" type="line">
				<view class="example-body">
					<easy-upload class="easy-upload" :dataList="formData.event" :autoUpload="true"
						:uploadUrl="getUploadUrl('event')" :uploadCount="20"
						@successImage="successImage($event,1,'event')" @successDeleteImg="successDeleteImg($event,'event')" />
				</view>
			</uni-section>
			<uni-section title="旅客信息" type="line">
				<view class="example-body">
					<easy-upload class="easy-upload" :dataList="formData.passenger" :autoUpload="true"
						:uploadUrl="getUploadUrl('passenger')" :uploadCount="20"
						@successImage="successImage($event,1,'passenger')" @successDeleteImg="successDeleteImg($event,'passenger')" />
				</view>
			</uni-section>
			<uni-section title="索赔、付款、赔偿单据" type="line">
				<view class="example-body">
					<easy-upload class="easy-upload" :dataList="formData.payPaper" :autoUpload="true"
						:uploadUrl="getUploadUrl('payPaper')"
						:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image"  :uploadCount="20"
						@successImage="successImage($event,1,'payPaper')" @successDeleteImg="successDeleteImg($event,'payPaper')" />
				</view>
			</uni-section>
			<uni-section title="付费票据等" type="line">
				<view class="example-body">
					<easy-upload class="easy-upload" :dataList="formData.ticket" :autoUpload="true"
						:uploadUrl="getUploadUrl('ticket')"
						:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image"  :uploadCount="20"
						@successImage="successImage($event,1,'ticket')" @successDeleteImg="successDeleteImg($event,'ticket')" />
				</view>
			</uni-section>
			<uni-section title="资金转账、审批单据" type="line">
				<view class="example-body">
					<easy-upload class="easy-upload" :dataList="formData.payApproval" :autoUpload="true"
						:uploadUrl="getUploadUrl('payApproval')"
						:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image"  :uploadCount="20"
						@successImage="successImage($event,1,'payApproval')" @successDeleteImg="successDeleteImg($event,'payApproval')" />
				</view>
			</uni-section>
			<uni-section title="航司授权" type="line">
				<view class="example-body">
					<easy-upload class="easy-upload" :dataList="formData.authorized" :autoUpload="true"
						:uploadUrl="getUploadUrl('authorized')"
						:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image"  :uploadCount="20"
						@successImage="successImage($event,1,'authorized')" @successDeleteImg="successDeleteImg($event,'authorized')" />
				</view>
			</uni-section>
			<uni-section title="其他" type="line">
				<view class="example-body">
					<easy-upload class="easy-upload" :dataList="formData.others" :autoUpload="true"
						:uploadUrl="getUploadUrl('')"
						:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image"  :uploadCount="20"
						@successImage="successImage($event,1,'others')" @successDeleteImg="successDeleteImg($event,'others')" />
				</view>
			</uni-section>
		</view>
	</view>
</template>

<script>
	import configService from '@/common/service/config.service.js';
	export default {
		data() {
			return {
				upLoadImgUrl: configService.apiUrl+'event/image/add',
				deleteImgUrl: configService.apiUrl+'event/image/remove',
				token: '',
				data: {},
				formData: {
					event:[],
					passenger: [],
					payPaper: [],
					ticket: [],
					payApproval: [],
					authorized: [],
					others:[]
				},

			}
		},
		onLoad(e) {
			this.token = uni.getStorageSync('token')
			if(e.data){
				this.data = JSON.parse(e.data);
				// console.log(this.data);
				this.setImgUrl()
			}
		},
		

		methods: {
			setImgUrl(){
				if(this.data.images.length){
					this.formData.event = this.data.images.filter(image => image.type === 'event') || [];
					this.formData.passenger = this.data.images.filter(image => image.type === 'passenger') || [];
					this.formData.payPaper = this.data.images.filter(image => image.type === 'payPaper') || [];
					this.formData.ticket = this.data.images.filter(image => image.type === 'ticket') || [];
					this.formData.payApproval = this.data.images.filter(image => image.type === 'payApproval') || [];
					this.formData.authorized = this.data.images.filter(image => image.type === 'authorized') || [];
					this.formData.others = this.data.images.filter(image => image.type === '') || [];
				}
			},
			getUploadUrl(type){
				return this.upLoadImgUrl + '?token='+ this.token + '&type='+type + '&eventId=' +this.data.eventId
			},
			getDeleteUrl(imageId){
				return this.deleteImgUrl + '?token='+ this.token + '&imageId='+imageId + '&eventId=' +this.data.eventId
			},
			// toNext(){
			// 	uni.navigateTo({
			// 		url: '/pages/index/accidentSignList'
			// 	})
			// },
			successImage(e,tabIdx,fieldName) {
				//debugger;
				console.log(e,JSON.parse(e.data),tabIdx,fieldName);
				// console.log(this.dataList);
				let uploadResult = JSON.parse(e.data)
				console.log(uploadResult);
				if (uploadResult.errcode == 0) {
					this.formData[fieldName].push(uploadResult.data.images[0])
					
				} else {
					
					uni.showToast({
						title: uploadResult.errmsg,
						icon: "none"
					})
				}
			},
			successDeleteImg(imgId,type) {
				console.log(22, imgId);

				this.$http.post(this.deleteImgUrl,{token:this.token,eventId:this.data.eventId,imageId:imgId}).then(res=>{
					// console.log(res)
					if(res.data.errcode == 0){
						// me.newsList=res.data.result.records
						this.formData[type] = this.formData[type].filter(item=>item.id!=imgId)
						uni.showToast({
							title: '删除成功',
							icon: "success"
						})
					}else{
						uni.showToast({
							title: res.data.errmsg,
							icon: "none"
						})
					}
				})
			},
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
			},
		}
	}
</script>

<style>
</style>